package com.zhida.common.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.*;

public class ObjectUtil {
    public static <K, V> boolean areAllValuesNotNull(HashMap<K, V> map) {
        for (V value : map.values()) {
            if (value == null || value.equals("")) {
                return false;
            }
        }
        return true;
    }
    public static List<Long> toList(Long ... delayMillis){
        return Arrays.asList(delayMillis);
    }

    public static <T> JsonNode JsonStr2Object(String jsonStr) throws JsonProcessingException {
        if (jsonStr == null || jsonStr.isEmpty()) {
            return null;
        }
        // 将json字符串转换成pojo
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readTree(jsonStr);
    }

    public static <T> String Object2JsonStr(T pojo) throws JsonProcessingException {
        // 将pojo转换成json字符串
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(pojo);
    }

    public static List<String> removeStringArrEmptyValue(String[] strings) {
        List<String> list = new ArrayList<>();
        for (String string : strings) {
            if (string != null && !string.equals("")) {
                list.add(string);
            }
        }
        return list;
    }

    public static String ListToStringWithChar(List<String> list , String splitChar){
//        将list的每个元素用splitChar连接并返回
        return String.join(splitChar, list);
    }
}
